import React from 'react';
import { Menu, Dropdown, Tooltip } from 'antd';
//@ts-ignore
import { EllipsisOutlined } from '#/utils/antdIcons';
import type { IPublishFQADataType } from '../../../type';
import { IOperationType } from '../../../type';
import { questionOperationList } from '../../../dictionary';
import styles from './index.less';

interface IProps {
  /**
   * 数据
   */
  data?: IPublishFQADataType;
  /**
   * 序号
   */
  order?: number;
  /**
   * 删除
   */
  onDetele?: (data?: IPublishFQADataType) => void;
  /**
   * 编辑
   */
  onEdit?: (data?: IPublishFQADataType) => void;
}

const FileItem = (props: IProps) => {
  const { onDetele, onEdit, data } = props;

  const onOperation = (e?: any) => {
    if (e?.key === IOperationType.DETELE) {
      onDetele && onDetele(data);
    } else {
      onEdit && onEdit(data);
    }
  };

  // 新增列表
  const menu = (
    <Menu onClick={onOperation}>
      {questionOperationList.map((item) => {
        return <Menu.Item key={item.value}>{item.label}</Menu.Item>;
      })}
    </Menu>
  );

  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <div className={styles.order}>{data?.rank ?? 0}</div>
        <div className={styles.more}>
          <Dropdown overlay={menu} placement="bottomRight" overlayClassName={styles.dropdownA}>
            <EllipsisOutlined />
          </Dropdown>
        </div>
      </div>
      <div className={styles.info}>
        <Tooltip
          title={data?.title ?? ''}
          placement={'bottomLeft'}
          overlayClassName={styles.overlayClassName}
        >
          <div className={styles.title}>{data?.title ?? ''} </div>
        </Tooltip>
        <div className={styles.answer}>
          <Tooltip
            title={data?.content ?? ''}
            placement={'bottomLeft'}
            overlayClassName={styles.overlayClassName}
          >
            <div className={styles.answerContent}>{data?.content ?? ''} </div>
          </Tooltip>
        </div>
      </div>
    </div>
  );
};

export default FileItem;
